package com.oywy.rbac.service;

import com.oywy.rbac.entity.Authority;
import com.oywy.rbac.repository.AuthorityRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.EntityNotFoundException;
import java.util.Collection;

/**
 * @author oywy
 * @date 2018/10/22
 */
@Service
public class AuthorityService {
    @Autowired
    private AuthorityRepository authorityRepo;

    public Collection<Authority> list() {
        return authorityRepo.findAll();
    }

    public Authority get(String id) {
        return authorityRepo.findById(id).orElseThrow(EntityNotFoundException::new);
    }

    public Authority post(Authority authority) {
        return authorityRepo.save(authority);
    }

    public Authority put(Authority authority) {
        return authorityRepo.save(authority);
    }

    public void del(String id) {
        authorityRepo.deleteById(id);
    }
}
